package com.flymobi.service;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import com.flymobi.fw.modules.CommonService;
import com.flymobi.fw.util.StringUtil;
import com.flymobi.po.Badwords;
import com.flymobi.util.QL;

public class BadwordsService extends CommonService {

	public List<Badwords> list(int startRow, int pagePerSize) {
		return dao.find(Badwords.class, QL.HQL.Badwords.LIST, new Object[] {},
				startRow, pagePerSize);
	}

	public Long getCount() {
		return dao.getCount(QL.HQL.Badwords.GET_COUNT, new Object[] {});
	}
	
	public void save(File file) {
		try {
			BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(file),"GBK"));  
			String line;
			int j=0;
			while ((line = br.readLine()) != null) {
				if(!StringUtil.isEmpty(line)){
					j++;
					System.out.println("badwords :"+j);
					Badwords bw=new Badwords();
					if(line.length()>20){
						line=line.substring(0,20);
					}
					bw.setWord(line);
					dao.save(bw);
				}
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void save(Badwords Badwords) {
		dao.save(Badwords);
	}

	public Badwords load(String id) {
		return dao.load(Badwords.class, new Long(id));
	}

	public Badwords get(String id) {
		return dao.get(Badwords.class, new Long(id));
	}

	public void delete(String id) {
		dao.delete(this.get(id));
	}
}
